package com.winse.java.options;

import junit.framework.Assert;

import com.winse.java.options.style.JavaSourceStyleTable;

/**
 * Conversion options for customizing the output result. You can adjust the
 * output style of a {@link de.java2html.converter.AbstractJavaSourceConverter}
 * by changing the attributes of this object. The color and font style are
 * defined by the {@link de.java2html.options.JavaSourceStyleTable} associated
 * with this options.
 * 
 * @see #setStyleTable(JavaSourceStyleTable)
 * @see #getStyleTable()
 * @see de.java2html.converter.AbstractJavaSourceConverter
 * 
 * @author <a href="mailto:markus@jave.de">Markus Gebhard</a>
 * 
 *         <code>Copyright (C) Markus Gebhard 2000-2003
 * 
 * This program is free software; you can redistribute it and/or
 *  * modify it under the terms of the GNU General Public License
 *  * as published by the Free Software Foundation; either version 2
 *  * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 *  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 *  * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.</code>
 */
public class JavaSourceConversionOptions {

	private static JavaSourceConversionOptions defaultOptions;

	public static JavaSourceConversionOptions getRawDefault() {
		return new JavaSourceConversionOptions();
	}

	public static JavaSourceConversionOptions getDefault() {
		if (defaultOptions == null) {
			defaultOptions = new JavaSourceConversionOptions();
		}
		return defaultOptions.getClone();
	}

	private JavaSourceStyleTable styleTable = JavaSourceStyleTable.getDefault();
	private int tabSize = 2;
	private boolean showLineNumbers = false;
	private boolean showFileName = false;
	private boolean showTableBorder = false;

	private JavaSourceConversionOptions() {
		// nothing to do
	}

	public boolean equals(Object obj) {
		if (!(obj instanceof JavaSourceConversionOptions)) {
			return false;
		}
		JavaSourceConversionOptions other = (JavaSourceConversionOptions) obj;
		return (other.tabSize == tabSize && other.styleTable.equals(styleTable) && other.showFileName == showFileName
				&& other.showLineNumbers == showLineNumbers && other.showTableBorder == showTableBorder);
	}

	public int hashCode() {
		return styleTable.hashCode() + tabSize;
	}

	public JavaSourceConversionOptions getClone() {
		JavaSourceConversionOptions options = new JavaSourceConversionOptions();
		options.styleTable = styleTable.getClone();
		options.tabSize = tabSize;
		options.showLineNumbers = showLineNumbers;
		options.showFileName = showFileName;
		options.showTableBorder = showTableBorder;
		return options;
	}

	public void setStyleTable(JavaSourceStyleTable styleTable) {
		Assert.assertNotNull(styleTable);
		this.styleTable = styleTable;
	}

	public JavaSourceStyleTable getStyleTable() {
		return styleTable;
	}

	public int getTabSize() {
		return tabSize;
	}

	public void setTabSize(int tabSize) {
		this.tabSize = tabSize;
	}

	public boolean isShowLineNumbers() {
		return showLineNumbers;
	}

	public void setShowLineNumbers(boolean showLineNumbers) {
		this.showLineNumbers = showLineNumbers;
	}

	public boolean isShowFileName() {
		return showFileName;
	}

	public boolean isShowTableBorder() {
		return showTableBorder;
	}

	public void setShowFileName(boolean showFileName) {
		this.showFileName = showFileName;
	}

	public void setShowTableBorder(boolean showTableBorder) {
		this.showTableBorder = showTableBorder;
	}

}